import requests
import json

headers = {
    "User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36",
}


url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule"

fw = input("请输入要翻译的内容")

data = {
    "i": fw,
    "from": "AUTO", #en
    "to": "AUTO", #zh-CHS
    "smartresult": "dict",
    "client": "fanyideskweb",
    "salt": 15621353229588,
    "sign": "53158e203fd5fa11505a6581ae333b29",
    "ts": "1562135322958",
    "bv": "3a019e7d0dda4bcd253903675f2209a5",
    "doctype": "json",
    "version": 2.1,
    "keyfrom": "fanyi.web",
    "action": "FY_BY_REALTlME",
}

response = requests.post(url,headers=headers,data=data)

dic = json.loads(response.text)
print(dic)

print(dic['translateResult'][0][0]['tgt'])